﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HZ.MBSM.DBUtility;
using System.Drawing;
public partial class Company_ProductAddJBzb : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAttorney);
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumCheckGoods);
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumComapanyRG);
        if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["ProductId"] == null)
                {
                    Response.Write("没有要添加的品目号！");
                }
                else
                {
                    HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
                    if (_Account != null)
                    {
                        Db db = new Db();
                        System.Data.IDataReader dr;
                        //取得商品信息
                        string strSql = "select * from product where Productid='" + Request.QueryString["ProductId"].ToString() + "'" ;
                        dr = db.DataReader(strSql);
                        while (dr.Read())
                        {
                            labProductCode.Text = dr["productid"].ToString();
                            labProductName.Text = SysFun.ToTrim(dr["productname"].ToString());//商品通用名
                            string _strMedicinemodel = dr["medicinemodel"].ToString();
                            string _strOutlookc = dr["outlookc"].ToString();
                            labMedicinemodel.Text = _strMedicinemodel;
                            labOutlookc.Text = _strOutlookc;
                            labunit.Text = dr["unit"].ToString();
                            labunintadd.Text =dr["unit"].ToString();
                            laboutadd.Text = _strOutlookc;
                        }
                        db.Close();
                        dr.Close();
                        dr.Dispose();
                    }
                }
            }
        }
    }
    //增补
    protected void BtnSave_Click(object sender, EventArgs e)
    {
          HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
          if (labOutlookc.Text.Trim().Equals(laboutadd.Text.Trim()) && labunit.Text.Trim().Equals(labunintadd.Text.Trim()))
          {
              Response.Write("<script>alert('请填写需要增补规格或单位！');</script>");
              return;
          }
          if (laboutadd.Text.Trim() == "")
          {
              Response.Write("<script>alert('请填写增补规格！');</script>");
              return;
          }
        HZ.MBSM.Model.Product pduct = new HZ.MBSM.Model.Product();
        pduct.Outlookc = laboutadd.Text.Trim();
        pduct.ProductName = labProductName.Text.Trim();
        pduct.Medicinemodel = labMedicinemodel.Text.Trim();
        pduct.Unit =labunintadd.Text.Trim();
        pduct.AccountidZB = _Account.AccountId.ToString();
        pduct.IScompanyADD = 1;
        pduct.fatherproductid = labProductCode.Text.Trim();
        HZ.MBSM.BLL.Product prodct = new HZ.MBSM.BLL.Product();
        if (prodct.SelectpucductExist(pduct))
        {
            HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "更新", "producct", "成功添加，目录号：" + labProductCode.Text.Trim() + "，原规格：" + labOutlookc.Text.Trim() + "+，增补规格+" + laboutadd.Text.Trim(), "../Company/productaddjbzb.aspx");
            Response.Write("<script>alert('增补成功！！！');window.opener.location.reload();window.opener=null;window.open('','_self');window.close();</script>");
        }
        else
        {
            HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "更新", "producct", "失败添加，目录号：" + labProductCode.Text.Trim() + "，原规格：" + labOutlookc.Text.Trim() + "+，增补规格+" + laboutadd.Text.Trim(), "../Company/productaddjbzb.aspx");
            Response.Write("<script>alert('该规格品种已经存在，增补失败！');</script>");
        }
       
    }
}
